package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootDj;
import org.footballmanager.pandafootball.system.service.FootDjService;
import org.footballmanager.pandafootball.system.service.impl.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/foot/footDj")
public class FootDjController extends AddAndEditController<FootDj> {
    /* 实体名称 */
    private static final String ENTITYNAME = "footDj";
    private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
    private static final String EDITPAGE = String.format(Constants.EDITPAGE, Constants.FOOT, ENTITYNAME);

    @Autowired
    private FootDjService footDjService;
    @Autowired
    private RedisService redisService;

    /**
     * 抽象方法
     *
     * @return 实体名称
     */
    @Override
    protected String getEntityName() {
        return ENTITYNAME;
    }

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @SuppressWarnings("unchecked")
    public String search(Model map) {
        List<FootDj> list = (List<FootDj>) redisService.get("listdj");
        map.addAttribute(String.format(Constants.LISTENTITY, ENTITYNAME), list);
        return LISTPAGE;
    }

    /**
     * 打开编辑球员等级页面
     *
     * @param map 参数
     * @param id  主键
     * @return 页面
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String openEditPage(Model map, @RequestParam Long id) {
        map.addAttribute(ENTITYNAME, footDjService.get(id));
        return EDITPAGE;
    }
}
